define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'broadcast/photo/index' + location.search,
                    edit_url: 'broadcast/photo/edit',
                    del_url: 'broadcast/photo/del',
                    table: 'broadcast_image_photo',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortOrder:'desc',
                search: false, //是否启用快速搜索
                commonSearch: true, //是否启用通用搜索
                searchFormVisible: true, //是否始终显示搜索表单
                titleForm: '', 
                showExport: false,
                singleSelect: false, 
                clickToSelect: true, //是否启用点击选中
                dblClickToEdit: false, //是否启用双击编辑
                showToggle: false,
                showColumns: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'broadcast_image_title', title: __('图组日期'),operate: false},
                        {field: 'broadcast_title', title: __('主题'),operate: false},
                        {field: 'admin_id', title: __('摄影师'),visible:false,searchList:$.getJSON('broadcast/photo/searchlist')},
                        {field:'custom',title:__('摄影师'),operate:false, formatter:function (value, row, index) {
                            if(row.admin_id > 1){
                            return row.admin.mobile+'['+row.admin.nickname+']';
                            }else{
                                return '';
                            }
                        }},
                        {field: 'image', title: __('图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field:'is_show',title:__('显示'),operate:false, formatter:function (value, row, index) {
                            if(row.is_show  ==  1){
                            return '<span class="text-success">开启</span>';
                            }else{
                                return '<span class="text-danger">关闭</span>';
                            }
                        }},
                        {field:'is_download',title:__('下载'),operate:false, formatter:function (value, row, index) {
                            if(row.is_download  == 1){
                                return '<span class="text-success">开启</span>'; 
                            }else{
                                return '<span class="text-danger">关闭</span>';
                            }
                        }},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                queryParams:function(params){
                    var filter=params.filter?JSON.parse(params.filter):{};
                    var op = params.op?JSON.parse(params.op):{};
                    filter.broadcast_image_id = Fast.api.query('bcid');
                    op.broadcast_image_id = '=';
                    filter.is_shift = 1;
                    op.is_shift = '=';
                    params.filter=JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                },

            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
